package com.gupaowork.pattern.proxy;

import com.gupaowork.pattern.proxy.dynamic.YiyanClassLoader;
import com.gupaowork.pattern.proxy.dynamic.YiyanInvocationHandler;
import com.gupaowork.pattern.proxy.dynamic.YiyanProxy;

import java.lang.reflect.Method;

/**
 * @Author heweicheng
 */
public class MeiPo implements YiyanInvocationHandler {

    private Object target;

    public Object getInstance(Object target) throws Exception {
        this.target = target;
        Class<?> clazz = target.getClass();
        return YiyanProxy.newProxyInstance(new YiyanClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(target, args);
        after();
        return obj;
    }

    private void before() {
        System.out.println("找到了一个高富帅");
    }

    private void after() {
        System.out.println("满意就结婚吧");
    }
}
